<?php
namespace Home\Controller;
use Think\Controller;
class CustController extends ZMController {
	/*
	0:上城区
	1:下城区
	2:江干区
	3:拱墅区
	4:西湖区
	5:滨江区
	6:萧山区
	7:余杭区
	8:桐庐县
	9:建德市
	10:富阳市
	11:临安市
	12:淳安县
	13:钱塘新区
	14:西湖风景区
	*/
    public function region(){//区域
		$Model=M();
		$res=$Model->query("select n,value from ddwk_customer_c1 where mid=5");
		$arr['n']='杭州市';
		$arr['value']=999;
		array_unshift($res,$arr);
		$this->ajaxReturn($res);
	}
	public function hospital($hid=NULL,$region=NULL){//监测医院
		$Model=M();
		if(empty($hid)){
			if($region===NULL||$region==''){
				$region=session('user.region');
			}
			$where='where 1=1';
			if($region!=999){
				$where.=" and region=$region";
			}
			$arr=$Model->db(1,'DB_CONFIG1')->query("select hid from ddwk_hospital $where and hid<>11");
			foreach($arr as $re){
				$hid.=','.$re['hid'];
			}
			$hid=ltrim($hid,',');
		}
		if(empty($hid)){
			return 0;
		}
		$res=$Model->db(1,'DB_CONFIG1')->query("select hid,name from ddwk_hospital where  hid in ($hid)");
		if(ACTION_NAME=='hospital'){
		    $this->ajaxReturn($res);
		}
		else{
			return $res;
		}
	}
	public function sessionRegion(){
		$region=session('user.region');
		$this->ajaxReturn($region);
	}
	public function hospname($hid){
		$Model=M();
		if(empty($hid)){
			return ;
		}
		$res=$Model->db(1,'DB_CONFIG1')->query("select name from ddwk_hospital where hid=$hid");
		return $res['0']['name'];
	}
	public function areaname($areaid){
		$Model=M();
		if(empty($areaid)){
			return ;
		}
		$res=$Model->db(1,'DB_CONFIG1')->query("select areaname from ddwk_area where id in ($areaid)");
		$areaname='';
		foreach($res as $row){
			$areaname.=','.$row['areaname'];
		}
		$areaname=ltrim($areaname,',');
		return $areaname;
	}
}